using Sirenix.OdinInspector;
using UnityEngine;
namespace DefaultNamespace.Skill
{
    [CreateAssetMenu(menuName = "Skills/AOE")]
    public class AOESkill: Skill
    {
        [LabelText("半径")]
        public float radius;
        [LabelText("伤害")]
        public float damage;
        public LayerMask targetLayers;
        
        public override void Activate(GameObject caster)
        {
            if (!IsReady()) return;
            
            // Play VFX/SFX
            if (castingVFX) Instantiate(castingVFX, caster.transform.position, Quaternion.identity);
            if (castSound) AudioSource.PlayClipAtPoint(castSound, caster.transform.position);
            
            // Detect targets
            Collider[] hits = Physics.OverlapSphere(caster.transform.position, radius, targetLayers);
            
            foreach (var hit in hits)
            {
                if (hit.gameObject != caster)
                {
                    HealthSystem health = hit.GetComponent<HealthSystem>();
                    if (health)
                    {
                        health.TakeDamage(damage);
                    }
                }
            }
            
            // Spawn impact effect
            if (impactVFX) Instantiate(impactVFX, caster.transform.position, Quaternion.identity);
            
            StartCooldown();
        }
    }
}